package com.sskjdata.cg.config;

import com.sskjdata.cg.interceptor.BseAccessLogInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

/**
 * @Desciption SpringBoot配置
 * @Author j
 * @Date 2018/6/18 16:30
 */
@Configuration
public class ChooseGoodsWebConfig implements WebMvcConfigurer {
    @Autowired
    private BseAccessLogInterceptor bseAccessLogInterceptor;

    @Bean
    public HttpMessageConverter<String> responseBodyConverter() {
        StringHttpMessageConverter converter = new StringHttpMessageConverter(
                Charset.forName("UTF-8"));
        return converter;
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(responseBodyConverter());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        ArrayList<String> list = new ArrayList<>();
        list.add("/**/*.js");
        list.add("/**/*.jpg");
        list.add("/**/*.jpeg");
        list.add("/**/*.png");
        list.add("/**/*.html");
        list.add("/**/*.css");
        list.add("/**/*.gif");
        list.add("/**/*.text");
        list.add("/**/*.txt");
        list.add( "/**/*.woff2");
        registry.addInterceptor(bseAccessLogInterceptor).addPathPatterns("/**").excludePathPatterns(list).
                excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");// 放行swagger 样式
    }
}
